#include <stdio.h>

#define MAX_VAR_NUM 100
#define MAX_INT 0xffffffff

typedef struct {
    int vex_num;
    unsigned int adj_mat[MAX_VAR_NUM][MAX_VAR_NUM];
}Graph;

void GetGraph(Graph *g);
void Floyd(Graph *g);

int main()
{
    Graph g;
    unsigned int p[MAX_VAR_NUM][MAX_VAR_NUM][MAX_VAR_NUM];

    GetGraph(&g);
    Floyd(&g);

    
    return 0;
}

void GetGraph(Graph *g)
{
    int i, j;
    scanf("%d", &g->vex_num);
    for (i = 0; i < g->vex_num; i++) {
        for (j = 0; j < g->vex_num; j++) {
            scanf("%d", &g->adj_mat[i][j]);
            if (g->adj_mat[i][j] == 0 && i != j) {
                g->adj_mat[i][j] = MAX_INT;
            }
        }
    }
    return;
}

void Floyd(Graph *g)
{
    int i, j, k, l;
    for (i = 0; i < g->vex_num; i++) {
        for (j = 0; j < g->vex_num; j++) {
            for (k = 0; k < g->vex_num; k++) {
                if (g->adj_mat[j][i] + g->adj_mat[i][k] < g->adj_mat[j][k]) {
                    g->adj_mat[j][k] = g->adj_mat[j][i] + g->adj_mat[i][k];
                }
            }
        }
    }

     for (i = 0; i < g->vex_num; i++) {
        for (j = 0; j < g->vex_num; j++) {
            printf("%2d ", g->adj_mat[i][j]);
        }
        putchar('\n');
    }

    return;
}


/*
  0  19  0  0  14  0   18
19   0    5   7   12   0   0
 0  5     0   3    0   0   0
 0  7   3     0    8    21  0
14  12  0  8     0    0   16
 0   0  0  21  0    0    27
18   0  0  0  16  27     0

*/